﻿
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


void menu()
{
	printf("******************************\n");
	printf("***---欢迎来到猜数字游戏---***\n");
	printf("*******--- 1. PLAY ---********\n");
	printf("*******--- 0. EXIT ---********\n");
}


void game()
{
	int guess = 0;
	int r = rand() % 100+1;
	//printf("r=%d\n", r);
	int count = 5;
	printf("本游戏总共有5次机会，次数耗尽则游戏结束\n");
	while (count) 
	{
		printf("请输入你猜的数字\n");
		scanf("%d", &guess);
		count--;
		if (guess != r)
		{
			printf("你还剩%d次机会\n",count);
	}
		

		 if (guess > r)
		{
			printf("你猜大了,请重新输入\n");
		}
		else if (guess<r)
		{
			printf("你猜小了,请重新输入\n");
		}
		else 
		 {
			 printf("恭喜你猜对了\n");
			 break;
		 }
		 if (count == 0)
		 {
			 printf("很遗憾，你的次数用完，游戏结束\n");
		 }
	}
	
}

int main()
{
	int input = 0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("请选择选项：");
		scanf("%d", &input);
		switch (input)
		{
		case 1: {
			printf("进入游戏，请猜数字\n");
			game();  break; }
		case 0: printf("退出游戏\n"); break;
		default:   printf("输入错误，请重新选择\n");


		}
	} 
	while (input);
	
	return 0;
}

